import WXRequest from './request'
// 导入基础配置变量
import { BASE_URL, TIME_OUT } from './request/config'
import LocalCache from '../ultills/cache'
const wxRequest = new WXRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  // 实例传入拦截器的一些配置
  interceptors: {
    requestInterceptor: (config) => {
      // 请求拦截判断是否携带token，并将token添加到请求头中去
      const token = LocalCache.getCache('token')

      if (token) {
        config.headers.Authorization = `Bearer ${token} `
      }

      return config
    },
    requestInterceptorCatch: (err) => {
      return err
    },
    responseInterceptor: (res) => {
      return res
    },
    responseInterceptorCatch: (err) => {
      return err
    }
  }
})
export default wxRequest
